package com.site.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.common.BaseController;
import com.entity.FactoryPhoto;
import com.service.ContactItemsService;
import com.service.FactoryPhotoService;
import com.service.ProductCategoryService;
import com.service.ProductionService;

@Controller
@RequestMapping("/")
public class FactoryPhotoController extends BaseController {
	@Autowired
	private ProductCategoryService productCategoryService;
	@Autowired
	private ProductionService productionService;
	@Autowired
	private ContactItemsService contactItemsService;
	@Autowired
	private FactoryPhotoService factoryPhotoService;
	@RequestMapping("/fctphoto/p{pageNo}")
	public String index(HttpServletRequest request, @PathVariable Integer pageNo){
		super.initCommon(request, productCategoryService, contactItemsService, productionService);
		if(pageNo == null)
			pageNo = 1;
		int total = this.factoryPhotoService.findCount();
		int pageNum = (total-1)/20+1;
		if(pageNo > pageNum)
			pageNo = pageNum;
		List<FactoryPhoto> page = this.factoryPhotoService.findInPage(20*(pageNo-1), 20);
		request.setAttribute("page", page);
		request.setAttribute("pageNo", pageNo);
		request.setAttribute("pageNum", pageNum);
		request.setAttribute("total", total);
		return "site.fctphoto";
	}
}
